//
//  RHPolicyConfigCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/3/12.
//

#import "RHPolicyConfigCell.h"
@interface RHPolicyConfigCell()
@property (nonatomic ,strong) UIImageView *statusIcon;
 
@property (nonatomic, strong) QMUILabel *powerContentLab;

@property (nonatomic, strong) QMUILabel *socContentLab;



@end
@implementation RHPolicyConfigCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

-(void)setPolicyModel:(RHPolicyModeModel *)policyModel
{
    _policyModel = policyModel;
    self.powerContentLab.text = ValidNullDataToString(policyModel.power, @"--");
    self.socContentLab.text = ValidNullDataToString(policyModel.soc, @"--");
    
    if([policyModel.power floatValue]>0){
        _statusIcon.image = [UIImage imageNamed:@"device_policy_chg"];
        _powerContentLab.textColor = kCOLOR_HEX(@"31D3AE");
        _socContentLab.textColor = kCOLOR_HEX(@"31D3AE");
    }else if([policyModel.power floatValue]<0){
        _statusIcon.image = [UIImage imageNamed:@"device_policy_dchg"];
        _powerContentLab.textColor = kCOLOR_HEX(@"678EF2");
        _socContentLab.textColor = kCOLOR_HEX(@"678EF2");
    }else{
        _statusIcon.image = [UIImage imageNamed:@"device_policy_none"];
        _powerContentLab.textColor = kCOLOR_HEX_A(@"3F4443", 0.6);
        _socContentLab.textColor = kCOLOR_HEX_A(@"3F4443",0.6);
    }
}

-(void)setupUI
{
    self.contentView.backgroundColor = CFTabViewBgColor;
    kWeakSelf;
    
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 15, 5, 15));
    }];
    
    _statusIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"device_policy_chg"]];
    [bgView addSubview:_statusIcon];
    [_statusIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(25);
        make.left.mas_offset(15);
        make.top.mas_offset(10);
    }];
    
    _timeLab = [[QMUILabel alloc]init];
    _timeLab.text = @"00:00-06:00";
    _timeLab.font = [UIFont systemFontOfSize:13];
    _timeLab.textAlignment = NSTextAlignmentLeft;
    _timeLab.textColor = kCOLOR_HEX(@"3F4443");
    [bgView addSubview:_timeLab];
    
    [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.statusIcon.mas_right).offset(5);
        make.centerY.equalTo(weakSelf.statusIcon);
    }];
    
    QMUIButton *btn = [[QMUIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"kwt_home_arrow"] forState:UIControlStateNormal];
    [bgView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(35);
        make.right.mas_offset(-5);
        make.centerY.equalTo(weakSelf.statusIcon);
    }];
    
    UIView *bgView1 = kView;
    bgView1.backgroundColor = CFTabViewBgColor;
    bgView1.layer.cornerRadius = 8;
    bgView1.layer.masksToBounds = YES;
    [bgView addSubview:bgView1];
    
    [bgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(weakSelf.timeLab.mas_bottom).offset(15);
        make.bottom.offset(-15);
        make.height.offset(kScaleW(80));
    }];
    
    
    
    UIView *line1 = kView;
    line1.backgroundColor = kCOLOR_HEX(@"E7E7E7");
    [bgView1 addSubview:line1];
    
    
    
    //功率
    QMUILabel *powerTitleLab = [[QMUILabel alloc]init];
    powerTitleLab.text = [NSString stringWithFormat:@"%@(kW)",@"功率".rh_localized];
    powerTitleLab.font = kSYSTEMFONT(12);
    powerTitleLab.textAlignment = NSTextAlignmentCenter;
    powerTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    [bgView1 addSubview:powerTitleLab];
    
    _powerContentLab = [[QMUILabel alloc]init];
    _powerContentLab.text = @"--";
    _powerContentLab.font = [UIFont systemFontOfSize:15];
    _powerContentLab.textAlignment = NSTextAlignmentCenter;
    _powerContentLab.textColor = kCOLOR_HEX(@"31D3AE");
    [bgView1 addSubview:_powerContentLab];
    
    //soc
    QMUILabel *socTitleLab = [[QMUILabel alloc]init];
    socTitleLab.text = [NSString stringWithFormat:@"%@(%%)",@"SOC".rh_localized];
    socTitleLab.font = kSYSTEMFONT(12);
    socTitleLab.textAlignment = NSTextAlignmentCenter;
    socTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    [bgView1 addSubview:socTitleLab ];
    
    _socContentLab = [[QMUILabel alloc]init];
    _socContentLab.text = @"--";
    _socContentLab.font = kSYSTEMFONT(18);
    _socContentLab.textAlignment = NSTextAlignmentCenter;
    _socContentLab.textColor = kCOLOR_HEX(@"31D3AE");
    [bgView1 addSubview:_socContentLab];

    
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.mas_offset(15);
        make.bottom.mas_offset(-15);
        make.width.offset(1);
    }];
    
   

    [powerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(10);
        make.left.mas_offset(0);
        make.right.equalTo(line1.mas_left);
    }];
    
    
    [_powerContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(powerTitleLab);
        make.right.equalTo(powerTitleLab);
        make.centerY.mas_offset(-10);
    }];
    
    
    
    [socTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line1.mas_right);
        make.right.mas_offset(0);
        make.centerY.equalTo(powerTitleLab);
    }];
    
    [_socContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line1.mas_right);
        make.right.mas_offset(0);
        make.centerY.equalTo(weakSelf.powerContentLab);
    }];
    
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.configBlock){
            weakSelf.configBlock();
        }
    }];
    
}

@end
